package com.phkj.qdh.ui.adapter

import android.content.Context
import android.view.RoundedCorner
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.hjq.shape.view.ShapeImageView
import com.phkj.qdh.R
import com.phkj.qdh.utils.dpToPx
import com.phkj.qdh.utils.gone
import com.phkj.qdh.utils.visible

class ImagerViewAdapter(private val isShow: Boolean = false) : BaseQuickAdapter<String, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: String?) {
        val iv = holder.getView<ShapeImageView>(R.id.iv)
        val options = RequestOptions.bitmapTransform(RoundedCorners(10f.dpToPx.toInt()))
        Glide.with(context).load(item).apply(options).into(iv)

        val ivDelete = holder.getView<ImageView>(R.id.iv_delete)
        if (isShow) ivDelete.gone() else ivDelete.visible()

    }

    override fun onCreateViewHolder(
        context: Context, parent: ViewGroup, viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_iv, parent)
    }
}